<template>
	<view class="mainPage content" :style="{'padding-top': `${$store.state.safeArea.top || 0}px`, 'padding-bottom': `${$store.state.safeArea.bottom || 0}px`}">
		<public-head :title="title"></public-head>
		<view style="height: 10rpx;"></view>
		<view class="box1" @click="changeImgs">
			<view class="left">头像</view>
			<view class="right">
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<!-- <u-action-sheet :list="meist" v-model="show" @click="changeImgs"></u-action-sheet> -->
		<view class="box1" @click="tomobile(info.user_account)">
			<view class="left">手机号码</view>
			<view class="right">
				<text>{{info.user_account}}</text>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="box1" @click="tomodify">
			<view class="left">修改登录密码</view>
			<view class="right">
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="box2" @click="quit">
			<view class="left">退出登录</view>
			<view class="right">
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
	</view>
</template>
<script>
var that
import publicHead from "@/components/publicHead/publicHead.vue"
export default {
	components: {
		publicHead
	},
	data() {
		return {
			title: "设置",
			mobile: '18798790657',
			meist: [{
				text: '拍照'
			}, {
				text: '从手机相册选择'
			}],
			show: false,
			imgUrl: "",
			info: ''
		}
	},
	onLoad() {
		that = this
		that.doctorInfo()
	},
	methods: {
		//上传头像
		changeImg() {
			this.show = true
		},
		changeImgs() {
			let that = this
			uni.chooseImage({
				count: 1,
				sourceType: ['camera', 'album'],
				success: (res) => {
					console.log(res)
					uni.getImageInfo({
						src: res.tempFilePaths[0],
						success: function (image) {
							let temp = {
								width: image.width,
								height: image.height,
								status: 3
							}
							// 前端拿到临时地址后请求接口

							/*res.tempFilePaths[0]是获取到的第一个数据的blob地址，将他赋值给数据区的imgUrl*/
							that.$util.uploadimgs('Doctor_uploadFile', res.tempFilePaths[0], temp, function (data) {
								console.log(data.data)
								data = JSON.parse(data.data)
								if (data.code == 1) {
									that.xiugai(data.data.url)
								} else {
									uni.showToast({
										title: '上传失败',
										icon: 'none',
										duration: 1500
									});
								}
							})
						}
					});
				}
			})
		},
		xiugai(e) {
			let postData = {
				upload_doctorAvatar: e
			}
			that.$postAjax1('PetDoctor_Center_avatar', postData, function (data) {
				uni.switchTab({
					url: '../../../pages/mine/mine'
				})
				uni.showToast({
					title: '上传成功',
					icon: 'none',
					duration: 1500
				});
			})
		},
		doctorInfo() {
			that.$postAjax1('Doctor_doctorInfo', {
			}, function (data) {
				that.info = data.data.data
				console.log('获取用户信息成功', that.info)
			})
		},
		tomobile(user_account) {
			console.log('获取到绑定的手机号', user_account)
			uni.navigateTo({
				url: './mobile?doc_oldphoneNum=' + user_account
			})
		},
		tomodify() {
			uni.navigateTo({
				url: 'cryptogram'
			})
		},
		quit() {
			uni.removeStorageSync('chongdoc_login');
			uni.showToast({
				icon: "none",
				title: '退出成功',
				duration: 1000
			});
			let promise = that.$tim.logout();
			promise.then(function (imResponse) {
				console.log('登出成功' + imResponse.data); // 登出成功
			}).catch(function (imError) {
				console.warn('logout error:', imError);
			});
			this.timer = setTimeout(() => {
				uni.reLaunch({
					url: '/pages/login/login'
				})
			}, 1000)
		}
	}
}
</script>
<style scoped lang="scss">
.content {
	width: 100vw;
	height: 100vh;
	background: #f6f6f6;
	// position: relative;
	.box1 {
		padding: 30rpx;
		background: #ffffff;
		//margin-top: 15rpx;
		.left {
			display: inline-block;
			width: 60%;
		}
		.right {
			display: inline-block;
			width: 40%;
			text-align: right;
		}
		text {
			color: #8a8a8a;
			margin-right: 20rpx;
		}
	}
	.box2 {
		padding: 30rpx;
		background: #ffffff;
		margin-top: 60rpx;
		.left {
			display: inline-block;
			width: 60%;
		}
		.right {
			display: inline-block;
			width: 40%;
			text-align: right;
		}
		text {
			color: #8a8a8a;
			margin-right: 20rpx;
		}
	}
}
</style>
